package cn.picclife.mwx.manager.sys.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.picclife.mwx.manager.sys.mapper.MenuMapper;
import cn.picclife.mwx.manager.sys.model.bo.MenuBo;
import cn.picclife.mwx.manager.sys.service.MenuMgMtService;
import cn.picclife.mwx.manager.util.uniqueseq.UniqueSeq;

@Service
public class MenuMgMtServiceImpl implements MenuMgMtService {
	@Autowired
	private MenuMapper menuMapper;

	@Override
	public List<MenuBo> queryMenu() {
		return menuMapper.queryMenu();
	}

	@SuppressWarnings("unused")
	@Override
	public int insertMenu(MenuBo menuBo) {
		Long menuNo = UniqueSeq.getUniqueSeq("menu_no", "t_menu");
		Long serno = UniqueSeq.getUniqueSeq("menu_id", "t_menu");
		String menuSeq = menuBo.getMenuSeq() + "." + serno;
		menuBo.setMenuNo(menuNo);
		menuBo.setMenuId(serno);
		menuBo.setMenuSeq(menuSeq);
		menuBo.setCrtDate(new Date());
		menuBo.setDataFlag("1");
		// menuBo.setCrtUser(crtUser);
		return menuMapper.insertMenu(menuBo);
	}

	@Override
	public MenuBo queryUpdateMenu(MenuBo menuBo) {
		return menuMapper.queryUpdateMenu(menuBo);
	}

	@Override
	public int updateMenuMgMt(MenuBo menuBo) {
		menuBo.setMdfDate(new Date());
		return menuMapper.updateMenuMgMt(menuBo);
	}

	@Override
	public int deleteMenuMgMt(String menuNo) {
		int num=0;
		Map<String, Object> map = new HashMap<>();
		map = menuMapper.queryMenuAuth(menuNo);
		if(null!=map.get("menu_no")&&!"".equals(map.get("menu_no"))) {
			menuMapper.deleteMenuAuth(map.get("menu_no").toString());
		}
		map = menuMapper.queryMenuMgMt(menuNo);
		if(null!=map.get("menu_seq")&&!"".equals(map.get("menu_seq"))) {
			num= menuMapper.deleteMenuMgMt(map.get("menu_seq").toString());
		}
        return num;
	}

	@Override
	public MenuBo queryCountMenu(MenuBo menuBo) {
		return menuMapper.queryCountMenu(menuBo);
	}

}
